package com.minosiants.dann.repository
import com.google.gson._
import java.lang.reflect.Type
import org.bson.types.ObjectId
import com.google.gson.reflect.TypeToken;import scala.collection.JavaConverters._
//"$oid" : "4d93646210c62168a52690b2"
class ObjectIdAdapter extends JsonSerializer[ObjectId] with  JsonDeserializer[ObjectId] {
		def serialize(src:ObjectId, typeOfSrc:Type , context:JsonSerializationContext )= {
			val jo=new JsonObject()
			jo.addProperty("$oid",src.toString)
			jo
		}
		def deserialize( json:JsonElement, typeOfT:Type , context:JsonDeserializationContext )={
			new ObjectId(json.getAsJsonObject().get("$oid").getAsString)
		}		
};class CollectionSerializer extends JsonSerializer[scala.collection.immutable.$colon$colon[_]] {     override def serialize(items: scala.collection.immutable.$colon$colon[_], objType: Type, context: JsonSerializationContext): JsonElement = {         val json = new JsonArray();         items.foreach(item => json.add(context.serialize(item)));        return json     }}
object Gson {	import com.minosiants.dann.data.Status
	def apply()=new GsonBuilder()
					.registerTypeAdapter(classOf[ObjectId], new ObjectIdAdapter())					//.registerTypeAdapter(classOf[scala.collection.immutable.$colon$colon[_]], new CollectionSerializer())
					.create
	
	def toJson(o:AnyRef)=Gson().toJson(o);	};